package com.adwin.addcoin.utils

import androidx.lifecycle.MutableLiveData
import com.adwin.addcoin.repository.bean.AppDispositionBean
import com.adwin.addcoin.repository.bean.InviteDetailsBean
import com.adwin.addcoin.repository.bean.UserCoinBean
import java.util.Random

object PersonalMessageUtils {
    var userCoinsBean = MutableLiveData<UserCoinBean>()
    var inviteDetailsBean = MutableLiveData<InviteDetailsBean>()
    var appDispositionBean = MutableLiveData<AppDispositionBean>()
    var inviteCode = ""
    var inviteNumber = 0L
    var inviteCoins = 0L

    private var characters = "0123456789qwertyuiopasdfghjklzxcvbnm"

    /**
     * 获取gaid
     */
    fun getUserGaid():String{
        val gaid = getStringLen(8)+ "-" +getStringLen(4)+"-"+ getStringLen(3)+"-"+ getStringLen(3)+"-"+ getStringLen(12)
        return gaid
    }

    private fun getStringLen(sizeOfRandomString:Int):String{
        val random = Random()
        val string = StringBuffer()
        for (i in 0 until sizeOfRandomString){
            val code = random.nextInt(characters.length-1)
            string.append(characters.substring(code,code+1))
        }
        return string.toString()
    }

    fun setAppDispositionBean(appDisposition: AppDispositionBean){
        appDispositionBean.value = appDisposition
    }

    fun setUserCoins(coinsBean : UserCoinBean){
       userCoinsBean.value = coinsBean
    }

    fun setInviteDetailsBean(inviteDetails: InviteDetailsBean){
        inviteDetailsBean.value = inviteDetails
        inviteCode = inviteDetails.inviteCode
        inviteNumber = inviteDetails.inviteNum
        inviteCoins = inviteDetails.inviteCoinNum
    }

    fun setInviteStatus(inviteStatus:Boolean){
        inviteDetailsBean.value?.inviteStatus = inviteStatus
    }
}